import React from 'react';
import { connect } from 'dva';
import {Form,Row,Col,DatePicker,Table,Pagination,Input,Button,Select} from 'antd';
const dateFormat="YYYY-MM-DD";
const {RangePicker}=DatePicker;
const Option=Select.Option;
const FormItem=Form.Item;
const R=require("ramda");
export default connect(({taxInvReport})=>({taxInvReport}))(
    Form.create()(class OrderCharge extends React.Component{
        constructor(props){
            super(props)
        }
        columns=[
            {title:"订单号",dataIndex:'orderNo',key:'orderNo'},
            {title:"合同协议号",dataIndex:'contractno',key:'contractno'},
            {title:"报关单号",dataIndex:'declaratNo',key:'declaratNo'},
            {title:"出口日期",dataIndex:'exportTime',key:'exportTime'},
            {title:"客户名称",dataIndex:'companyname',key:'companyname'},
            {title:"退税金额",dataIndex:'drawbackAmount',key:'drawbackAmount'},
            {title:"放行状态",dataIndex:'passStatus',key:'passStatus'},
            {title:"外汇状态",dataIndex:'foxerStatus',key:'foxerStatus'},
            {title:"发票状态",dataIndex:'invoiceStatus',key:'invoiceStatus'},
            {title:"退税融资状态",dataIndex:'drawbackFianceStatus',key:'drawbackFianceStatus'},
            {title:"交单税局状态",dataIndex:'presentStatus',key:'presentStatus'},
            {title:"退税款到账状态",dataIndex:'transferAccountStatus',key:'transferAccountStatus'},
            {title: '预开票',
                render(record){
                    return record.isperopeninvoice === "2" ? "是" : "否";
                }
            },

        ];


        // handleCstChange=(value)=>{
        //     this.props.dispatch({
        //                             type:"taxInvReport/getCstBaseInfo",
        //                             payload:{
        //                                 cstId:value
        //                             }
        //                         })
        //
        // }


        handleSearch=()=>{
            let values=this.props.form.getFieldsValue();
            let times=values.time;
            //console.log(values);
            this.props.dispatch({
                type:"taxInvReport/getTaxStatus",
                payload:{
                    cstId:values.cstId,
                    orderNo:values.orderno,
                    declaratNo:values.declaratNo,
                    drawbackFianceStatus:values.drawbackFianceStatus,
                    presentStatus:values.presentStatus,
                    transferAccountStatus:values.transferAccountStatus,
                    beginTime:R.isNil(times)||R.isEmpty(times)?null:times[0].format(dateFormat),
                    endTime:R.isNil(times)||R.isEmpty(times)?null:times[1].format(dateFormat),
                }
            })

        }

        handleExport=()=>{
            let values=this.props.form.getFieldsValue();
            let times=values.time;
            this.props.dispatch({
                type:"taxInvReport/exportTaxStatus",
                payload:{
                    cstId:R.isNil(values.cstId)?'':values.cstid,
                    orderNo:R.isNil(values.orderno)?'':values.orderno,
                    declaratNo:R.isNil(values.declaratNo)?'':values.declaratNo,
                    drawbackFianceStatus:R.isNil(values.drawbackFianceStatus)?'':values.drawbackFianceStatus,
                    presentStatus:R.isNil(values.presentStatus)?'':values.presentStatus,
                    transferAccountStatus:R.isNil(values.transferAccountStatus)?'':values.transferAccountStatus,
                    beginTime:R.isNil(times)||R.isEmpty(times)?'':times[0].format(dateFormat),
                    endTime:R.isNil(times)||R.isEmpty(times)?'':times[1].format(dateFormat),
                }
            })
        }


        render(){

            let pagination={

                showTotal: total => `共 ${total} 条数据`,
                pageSize: this.props.taxInvReport.page.size,
                total: this.props.taxInvReport.page.totalRow,
                showSizeChanger: true,
                current:this.props.taxInvReport.page.page,
                onShowSizeChange: (current, size) => {
                    let values=this.props.form.getFieldsValue();
                    let times=values.time;
                    let newPage = this.props.taxInvReport.page;
                    newPage.size = size;
                    newPage.page = 1;
                    this.props.dispatch({
                        type: 'taxInvReport/getTaxStatus',
                        payload: {
                            cstId:values.cstId,
                            orderNo:values.orderno,
                            declaratNo:values.declaratNo,
                            drawbackFianceStatus:values.drawbackFianceStatus,
                            presentStatus:values.presentStatus,
                            transferAccountStatus:values.transferAccountStatus,
                            beginTime:R.isNil(times)||R.isEmpty(times)?null:times[0].format(dateFormat),
                            endTime:R.isNil(times)||R.isEmpty(times)?null:times[1].format(dateFormat),
                            page:newPage,
                        }
                    });
                },

                onChange: (pageNumber, pageSize) => {
                    let values=this.props.form.getFieldsValue();
                    let times=values.time;
                    let newPage = this.props.taxInvReport.page;
                    newPage.page = pageNumber;
                    newPage.pageSize=pageSize;
                    this.props.dispatch({
                        type: 'taxInvReport/getTaxStatus',
                        payload: {
                            cstId:values.cstId,
                            orderNo:values.orderno,
                            declaratNo:values.declaratNo,
                            drawbackFianceStatus:values.drawbackFianceStatus,
                            presentStatus:values.presentStatus,
                            transferAccountStatus:values.transferAccountStatus,
                            beginTime:R.isNil(times)||R.isEmpty(times)?null:times[0].format(dateFormat),
                            endTime:R.isNil(times)||R.isEmpty(times)?null:times[1].format(dateFormat),
                            page:newPage,
                        }
                    });
                }


            };
            let dataSource=R.isNil(this.props.taxInvReport.taxStatusList)?null:this.props.taxInvReport.taxStatusList;
            const {getFieldDecorator}=this.props.form;
            let formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 18 } };

            // let options=[];
            // let cstList=R.isNil(this.props.cstList)?[]:this.props.cstList;
            // console.log(cstList);
            // cstList.forEach((item)=>{
            //     options.push(<Option key={item}></Option>)
            // })
            return(
                <Form>
                    <div>
                        <Row>
                            <Col span={7}>
                                <FormItem {...formItemLayout} label={'订单号'}>
                                    {getFieldDecorator('orderno', {})(
                                        <Input/>
                                    )}
                                </FormItem>
                            </Col>
                            <Col span={7}>
                                <FormItem {...formItemLayout} label={'报关单号'}>
                                    {getFieldDecorator('declaratNo', {})(
                                        <Input/>
                                    )}
                                </FormItem>
                            </Col>
                        </Row>
                        <Row>
                            <Col span={7}>
                                <FormItem
                                    {...formItemLayout}
                                    label={'退税融资款释放'}
                                >
                                    {getFieldDecorator('drawbackFianceStatus', {

                                    })(
                                        <Select style={{width: '100%'}}>
                                            <Option value="">全部</Option>
                                            <Option value="1">已释放</Option>
                                            <Option value="0">未释放</Option>
                                        </Select>
                                    )}
                                </FormItem>
                            </Col>
                            <Col span={7}>
                                <FormItem
                                    {...formItemLayout}
                                    label={'交单税局状态'}
                                >
                                    {getFieldDecorator('presentStatus', {

                                    })(
                                        <Select style={{width: '100%'}}>
                                            <Option value="">全部</Option>
                                            <Option value="1">已交单</Option>
                                            <Option value="0">未交单</Option>
                                        </Select>
                                    )}
                                </FormItem>
                            </Col>
                        </Row>
                        <Row>
                            <Col span={7}>
                                <FormItem
                                    {...formItemLayout}
                                    label={'退税款到账'}
                                >
                                    {getFieldDecorator('transferAccountStatus', {
                                        // initialValue: R.isNil(search.transferAccountStatus) ? '' : search.transferAccountStatus
                                    })(
                                        <Select style={{width: '100%'}}>
                                            <Option value="">全部</Option>
                                            <Option value="0">待退税</Option>
                                            <Option value="1">退税款到账</Option>
                                            <Option value="2">暂缓退税</Option>
                                            <Option value="3">税局发函</Option>
                                        </Select>
                                    )}
                                </FormItem>
                            </Col>
                            <Col span={7}>
                                <FormItem {...formItemLayout} label={'出口日期'}>
                                    {getFieldDecorator('time', {
                                        // initialValue:
                                        //     [ search.exportStart == '' ? '' : moment(search.exportStart, dateFormat), search.exportEnd == '' ? '' :moment(search.exportEnd, dateFormat)]
                                    })(
                                        <RangePicker
                                            showTime={{ format: 'YYYY-MM-DD' }}
                                            format="YYYY-MM-DD"
                                            placeholder={['开始时间', '结束时间']}
                                        />
                                    )}
                                </FormItem>
                            </Col>


                        </Row>
                        <Row>
                            <Col span={7}>
                                <FormItem {...formItemLayout} label={'客户名称'}>
                                    {getFieldDecorator('cstId',{})(
                                     <Input/>
                                    )}
                                </FormItem>
                            </Col>
                            <Col span={4} style={{textAlign: 'right'}}>
                            <Button type="primary" icon="search" style={{marginRight: 5}} onClick={this.handleSearch.bind(this)}>查询</Button>
                            </Col>
                            <Col span={4} style={{textAlign: 'right'}}>
                            <Button type="primary" icon="search" style={{marginRight: 5}} onClick={this.handleExport.bind(this)}>导出数据</Button>
                            </Col>
                        </Row>
                    </div>
                    <Row>
                        <Table dataSource={dataSource} pagination={pagination} size={'middle'} columns={this.columns} bordered={true}/>
                    </Row>
                </Form>


            )
        }


    })
)